//
//  HDCFFundDetailMiddleView.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/11/1.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "HDCFFundDetailMiddleView.h"
#import <WebKit/WebKit.h>
#import "SVProgressHUD.h"

#define KFundList @"/public/product/get-fund-type-performance-chart"

@interface HDCFFundDetailMiddleView ()<WKUIDelegate, WKNavigationDelegate>

@property (weak, nonatomic) IBOutlet UISegmentedControl *segment;

@property (weak, nonatomic) IBOutlet UIButton *oneMonth;
@property (weak, nonatomic) IBOutlet UIButton *threeNounth;
@property (weak, nonatomic) IBOutlet UIButton *oneYear;
@property (weak, nonatomic) IBOutlet UIButton *threeYear;
@property (weak, nonatomic) IBOutlet UIButton *fiveYear;
@property (weak, nonatomic) IBOutlet UIButton *forver;
@property (weak, nonatomic) IBOutlet UIView *sliderView;
@property (nonatomic, strong) NSArray *btnArray;

@property (nonatomic, weak) WKWebView *webView;
@property (nonatomic, strong) NSMutableArray *rateData;
@property (nonatomic, strong) NSMutableArray *timeData;

@property (nonatomic, strong) NSMutableArray *oneOneMounth;
@property (nonatomic, strong) NSMutableArray *oneThreeMounth;
@property (nonatomic, strong) NSMutableArray *oneOneYear;
@property (nonatomic, strong) NSMutableArray *oneThreeYear;
@property (nonatomic, strong) NSMutableArray *oneFiveYear;
@property (nonatomic, strong) NSMutableArray *oneEver;;
@property (nonatomic, strong) NSMutableArray *twoOneMounth;
@property (nonatomic, strong) NSMutableArray *twoThreeMounth;
@property (nonatomic, strong) NSMutableArray *twoOneYear;
@property (nonatomic, strong) NSMutableArray *twoThreeYear;
@property (nonatomic, strong) NSMutableArray *twoFiveYear;
@property (nonatomic, strong) NSMutableArray *twoEver;

@property (nonatomic, assign) BOOL isOneYes;

@end

@implementation HDCFFundDetailMiddleView

- (NSMutableArray *)oneOneMounth{
    if (!_oneOneMounth) {
        self.oneOneMounth = [NSMutableArray array];
    }
    return _oneOneMounth;
}

- (NSMutableArray *)oneThreeMounth{
    if (!_oneThreeMounth) {
        self.oneThreeMounth = [NSMutableArray array];
    }
    return _oneThreeMounth;
}

- (NSMutableArray *)oneOneYear{
    if (!_oneOneYear) {
        self.oneOneYear = [NSMutableArray array];
    }
    return _oneOneYear;
}

- (NSMutableArray *)oneThreeYear{
    if (!_oneThreeYear) {
        self.oneThreeYear = [NSMutableArray array];
    }
    return _oneThreeYear;
}

- (NSMutableArray *)oneFiveYear{
    if (!_oneFiveYear) {
        self.oneFiveYear = [NSMutableArray array];
    }
    return _oneFiveYear;
}

- (NSMutableArray *)oneEver{
    if (!_oneEver) {
        self.oneEver = [NSMutableArray array];
    }
    return _oneEver;
}

- (NSMutableArray *)twoOneMounth{
    if (!_twoOneMounth) {
        self.twoOneMounth = [NSMutableArray array];
    }
    return _twoOneMounth;
}

- (NSMutableArray *)twoThreeMounth{
    if (!_twoThreeMounth) {
        self.twoThreeMounth = [NSMutableArray array];
    }
    return _twoThreeMounth;
}

- (NSMutableArray *)twoOneYear{
    if (!_twoOneYear) {
        self.twoOneYear = [NSMutableArray array];
    }
    return _twoOneYear;
}

- (NSMutableArray *)twoThreeYear{
    if (!_twoThreeYear) {
        self.twoThreeYear = [NSMutableArray array];
    }
    return _twoThreeYear;
}

- (NSMutableArray *)twoFiveYear{
    if (!_twoFiveYear) {
        self.twoFiveYear = [NSMutableArray array];
    }
    return _twoFiveYear;
}

- (NSMutableArray *)twoEver{
    if (!_twoEver) {
        self.twoEver = [NSMutableArray array];
    }
    return _twoEver;
}

- (IBAction)segClick:(UISegmentedControl *)sender {
//    [self deleteWebCache];
    
    if (sender.selectedSegmentIndex == 0) {
        self.isOneYes = YES;
        NSMutableDictionary *htmlDict = [NSMutableDictionary dictionary];
        if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
            NSMutableArray *dataArray = [NSMutableArray array];
            NSMutableArray *timeArray = [NSMutableArray array];
            for (int i = 0; i < _oneOneMounth.count; i++) {
                NSDictionary *dict = _oneOneMounth[i];
                [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
                [timeArray addObject:dict[@"navDate"]];
            }
            htmlDict[@"xData"] = timeArray;
            htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
            htmlDict[@"legend"] = [NSArray arrayWithObjects:@"7日年化收益率(%)", nil];
            NSString *str = [self dictionaryToJson:htmlDict];
            NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
            [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                //TODO
            }];
        }else{
            NSMutableArray *dataArray = [NSMutableArray array];
            NSMutableArray *timeArray = [NSMutableArray array];
            for (int i = 0; i < _oneOneMounth.count; i++) {
                NSDictionary *dict = _oneOneMounth[i];
                [dataArray addObject:dict[@"performance"]];
                [timeArray addObject:dict[@"navDate"]];
            }
            htmlDict[@"xData"] = timeArray;
            htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
            htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
            NSString *str = [self dictionaryToJson:htmlDict];
            NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
            [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                //TODO
            }];
        }
    }else{
        NSMutableDictionary *htmlDict = [NSMutableDictionary dictionary];
        self.isOneYes = NO;
        if (_twoOneMounth.count > 0) {
            if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                NSMutableArray *dataArray = [NSMutableArray array];
                NSMutableArray *timeArray = [NSMutableArray array];
                for (int i = 0; i < _twoOneMounth.count; i++) {
                    NSDictionary *dict = _twoOneMounth[i];
                    [dataArray addObject:dict[@"earningsPer10000"]];
                    [timeArray addObject:dict[@"navDate"]];
                }
                htmlDict[@"xData"] = timeArray;
                htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                htmlDict[@"legend"] = [NSArray arrayWithObjects:@"万份收益(元)", nil];
                NSString *str = [self dictionaryToJson:htmlDict];
                NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                    //TODO
                }];
            }else{
                NSMutableArray *dataArray = [NSMutableArray array];
                NSMutableArray *timeArray = [NSMutableArray array];
                for (int i = 0; i < _twoOneMounth.count; i++) {
                    NSDictionary *dict = _twoOneMounth[i];
                    [dataArray addObject:dict[@"nav"]];
                    [timeArray addObject:dict[@"navDate"]];
                }
                htmlDict[@"xData"] = timeArray;
                htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                htmlDict[@"legend"] = [NSArray arrayWithObjects:@"净值走势(元)", nil];
                NSString *str = [self dictionaryToJson:htmlDict];
                NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                    //TODO
                }];
            }
        }else{
            [self getDataOneMounthWithPeriod:@"1"];
        }
    
    }
    [self setBtnColorWithBtn:_oneMonth];
}

//@"MM":@"货币型",
//@"BOND":@"债券型",
//@"MIXED":@"混合型",
//@"CP":@"保本型",
//@"EQ":@"股票型",
//@"AI":@"另类型",
//@"INDEX":@"指数型",
//@"ST":@"分级型",
//@"UNKNOWN":@"其他"

- (void)setDataDict:(NSDictionary *)dataDict{
    _dataDict = dataDict;
    _isOneYes = YES;
    NSString *fundType = dataDict[@"fundType"];
    if ([fundType isEqualToString:@"MM"]) {
        [_segment setTitle:@"7日年化收益率" forSegmentAtIndex:0];
        [_segment setTitle:@"万分收益" forSegmentAtIndex:1];
    }else{
        [_segment setTitle:@"收益走势" forSegmentAtIndex:0];
        [_segment setTitle:@"净值走势" forSegmentAtIndex:1];
    }
    [self getDataOneMounthWithPeriod:@"1"];
}

- (void)getDataOneMounthWithPeriod:(NSString *)period{
    NSMutableDictionary *paramets = [NSMutableDictionary dictionary];
    paramets[@"fundCode"] = _dataDict[@"fundCode"];
    paramets[@"period"] = period;
    NSString *jsonStr = [self dictionaryToJson:paramets];
    NSDictionary *paramet = @{KparametOne:jsonStr,
                              KparametTwo:@"/public/product/find-fund-performance"};
    
    [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
        NSString *code = result[@"code"];
        if ([code isEqualToString:@"0000"]) {
            NSDictionary *dict = result[@"data"];
            if (_isOneYes == YES) {
                NSMutableDictionary *htmlDict = [NSMutableDictionary dictionary];
                if ([period isEqualToString:@"1"]) {
                    [self.oneOneMounth addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneOneMounth.count; i++) {
                            NSDictionary *dict = _oneOneMounth[i];
                            [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"七日年化收益率(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneOneMounth.count; i++) {
                            NSDictionary *dict = _oneOneMounth[i];
                            [dataArray addObject:dict[@"performance"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else if([period isEqualToString:@"2"]){
                    [self.oneThreeMounth addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneThreeMounth.count; i++) {
                            NSDictionary *dict = _oneThreeMounth[i];
                            [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"七日年化收益率(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneThreeMounth.count; i++) {
                            NSDictionary *dict = _oneThreeMounth[i];
                            [dataArray addObject:dict[@"performance"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else if([period isEqualToString:@"4"]){
                    [self.oneOneYear addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneOneYear.count; i++) {
                            NSDictionary *dict = _oneOneYear[i];
                            [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"七日年化收益率(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneOneYear.count; i++) {
                            NSDictionary *dict = _oneOneYear[i];
                            [dataArray addObject:dict[@"performance"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else if([period isEqualToString:@"5"]){
                    [self.oneThreeYear addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneThreeYear.count; i++) {
                            NSDictionary *dict = _oneThreeYear[i];
                            [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"七日年化收益率(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneThreeYear.count; i++) {
                            NSDictionary *dict = _oneThreeYear[i];
                            [dataArray addObject:dict[@"performance"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else if([period isEqualToString:@"6"]){
                    [self.oneFiveYear addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneFiveYear.count; i++) {
                            NSDictionary *dict = _oneFiveYear[i];
                            [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"七日年化收益率(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneFiveYear.count; i++) {
                            NSDictionary *dict = _oneFiveYear[i];
                            [dataArray addObject:dict[@"performance"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else{
                    [self.oneEver addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneEver.count; i++) {
                            NSDictionary *dict = _oneEver[i];
                            [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"七日年化收益率(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _oneEver.count; i++) {
                            NSDictionary *dict = _oneEver[i];
                            [dataArray addObject:dict[@"performance"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }
            }else{
                NSMutableDictionary *htmlDict = [NSMutableDictionary dictionary];
                if ([period isEqualToString:@"1"]) {
                    [self.twoOneMounth addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoOneMounth.count; i++) {
                            NSDictionary *dict = _twoOneMounth[i];
                            [dataArray addObject:dict[@"earningsPer10000"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"万份收益(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoOneMounth.count; i++) {
                            NSDictionary *dict = _twoOneMounth[i];
                            [dataArray addObject:dict[@"nav"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"净值走势(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else if([period isEqualToString:@"2"]){
                    [self.twoThreeMounth addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoThreeMounth.count; i++) {
                            NSDictionary *dict = _twoThreeMounth[i];
                            [dataArray addObject:dict[@"earningsPer10000"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"万份收益(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoThreeMounth.count; i++) {
                            NSDictionary *dict = _twoThreeMounth[i];
                            [dataArray addObject:dict[@"nav"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"净值走势(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else if([period isEqualToString:@"4"]){
                    [self.twoOneYear addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoOneYear.count; i++) {
                            NSDictionary *dict = _twoOneYear[i];
                            [dataArray addObject:dict[@"earningsPer10000"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"万份收益(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoOneYear.count; i++) {
                            NSDictionary *dict = _twoOneYear[i];
                            [dataArray addObject:dict[@"nav"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"净值走势(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else if([period isEqualToString:@"5"]){
                    [self.twoThreeYear addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoThreeYear.count; i++) {
                            NSDictionary *dict = _twoThreeYear[i];
                            [dataArray addObject:dict[@"earningsPer10000"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"万份收益(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoThreeYear.count; i++) {
                            NSDictionary *dict = _twoThreeYear[i];
                            [dataArray addObject:dict[@"nav"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"净值走势(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else if([period isEqualToString:@"6"]){
                    [self.twoFiveYear addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoFiveYear.count; i++) {
                            NSDictionary *dict = _twoFiveYear[i];
                            [dataArray addObject:dict[@"earningsPer10000"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"万份收益(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoFiveYear.count; i++) {
                            NSDictionary *dict = _twoFiveYear[i];
                            [dataArray addObject:dict[@"nav"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"净值走势(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }else{
                    [self.twoEver addObjectsFromArray:dict[@"performance"]];
                    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoEver.count; i++) {
                            NSDictionary *dict = _twoEver[i];
                            [dataArray addObject:dict[@"earningsPer10000"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"万份收益(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }else{
                        NSMutableArray *dataArray = [NSMutableArray array];
                        NSMutableArray *timeArray = [NSMutableArray array];
                        for (int i = 0; i < _twoEver.count; i++) {
                            NSDictionary *dict = _twoEver[i];
                            [dataArray addObject:dict[@"nav"]];
                            [timeArray addObject:dict[@"navDate"]];
                        }
                        htmlDict[@"xData"] = timeArray;
                        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"净值走势(元)", nil];
                        NSString *str = [self dictionaryToJson:htmlDict];
                        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                            //TODO
                        }];
                    }
                }
            }
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.0];
        }
        
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"服务器错误"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}

- (NSArray *)btnArray{
    if (!_btnArray) {
        self.btnArray = [NSArray arrayWithObjects:self.oneMonth, self.threeNounth, self.oneYear, self.threeYear, self.fiveYear, self.forver, nil];
    }
    return _btnArray;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self test];
    }
    return self;
}

- (NSMutableArray *)timeData{
    if (!_timeData) {
        self.timeData = [NSMutableArray array];
        
    }
    return _timeData;
}

- (NSMutableArray *)rateData{
    if (!_rateData) {
        self.rateData = [NSMutableArray array];
        
    }
    return _rateData;
}

- (NSString *)getDateStringWith:(NSNumber *)ti{
    NSNumber *navDate = ti;
    NSDateFormatter *stampFormatter = [[NSDateFormatter alloc] init];
    [stampFormatter setDateFormat:@"YYYY-MM-dd"];
    NSDate *stampDate2 = [NSDate dateWithTimeIntervalSince1970:[navDate doubleValue] / 1000];
    NSString *dateString = [stampFormatter stringFromDate:stampDate2];
    return dateString;
}

- (NSString *)dictionaryToJson:(NSDictionary *)dic{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString *finalStr = [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    return finalStr;
}

- (void)test{
    WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    CGRect rect = CGRectMake(0, 41, screenWidth, 165);
    WKWebView *webview = [[WKWebView alloc] initWithFrame:rect configuration:config];
    webview.navigationDelegate = self;
    webview.scrollView.scrollEnabled = YES;
    webview.UIDelegate = self;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"echarts" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    [webview loadRequest:[NSURLRequest requestWithURL:url]];
    [self addSubview:webview];
    _webView = webview;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    _segment.tintColor = ZKcolor(182, 27, 36);
    [_oneMonth setTitleColor:ZKcolor(184, 27, 36) forState:UIControlStateNormal];
    WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    CGRect rect = CGRectMake(0, 41, screenWidth, 165);
    WKWebView *webview = [[WKWebView alloc] initWithFrame:rect configuration:config];
    webview.navigationDelegate = self;
    webview.scrollView.scrollEnabled = NO;
    webview.UIDelegate = self;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"echarts" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    [webview loadRequest:[NSURLRequest requestWithURL:url]];
    [self addSubview:webview];
    _webView = webview;
}

-(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    
}

-(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
    
}

-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    NSMutableDictionary *htmlDict = [NSMutableDictionary dictionary];
    if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
        NSMutableArray *dataArray = [NSMutableArray array];
        NSMutableArray *timeArray = [NSMutableArray array];
        for (int i = 0; i < _oneOneMounth.count; i++) {
            NSDictionary *dict = _oneOneMounth[i];
            [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
            [timeArray addObject:dict[@"navDate"]];
        }
        htmlDict[@"xData"] = timeArray;
        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"7日年化收益率(%)", nil];
        NSString *str = [self dictionaryToJson:htmlDict];
        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
            //TODO
        }];
    }else{
        NSMutableArray *dataArray = [NSMutableArray array];
        NSMutableArray *timeArray = [NSMutableArray array];
        for (int i = 0; i < _oneOneMounth.count; i++) {
            NSDictionary *dict = _oneOneMounth[i];
            [dataArray addObject:dict[@"performance"]];
            [timeArray addObject:dict[@"navDate"]];
        }
        htmlDict[@"xData"] = timeArray;
        htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
        htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
        NSString *str = [self dictionaryToJson:htmlDict];
        NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
        [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
            //TODO
        }];
    }
}

- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
{
//    UIAlertController *alertView = [UIAlertController alertControllerWithTitle:@"JS-Coder" message:message preferredStyle:UIAlertControllerStyleAlert];
//
//    [alertView addAction:[UIAlertAction actionWithTitle:@"Sure" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        //一定要调用下这个block
//        //API说明：The completion handler to call after the alert panel has been dismissed
//        completionHandler();
//    }]];
    
//    UIAlertView *alert = [UIAlertView alloc] initWithTitle:@"123" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil]
    
}

+ (instancetype)HDCFFundDetailMiddleView{
    return [[NSBundle mainBundle] loadNibNamed:@"HDCFFundDetailMiddleView" owner:nil options:nil].firstObject;
}

- (void)changeChartWithArray:(NSMutableArray *)dataAry withDataArrayTwo:(NSMutableArray *)dataAryTwo withPage:(BOOL)page withPorid:(NSString *)proid{
    NSMutableDictionary *htmlDict = [NSMutableDictionary dictionary];
    if (page == YES) {
        if (dataAry.count > 0) {
            if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                NSMutableArray *dataArray = [NSMutableArray array];
                NSMutableArray *timeArray = [NSMutableArray array];
                for (int i = 0; i < dataAry.count; i++) {
                    NSDictionary *dict = dataAry[i];
                    [dataArray addObject:dict[@"sevenDaysAnnualizedYield"]];
                    [timeArray addObject:dict[@"navDate"]];
                }
                htmlDict[@"xData"] = timeArray;
                htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                htmlDict[@"legend"] = [NSArray arrayWithObjects:@"七日年化收益率(%)", nil];
                NSString *str = [self dictionaryToJson:htmlDict];
                NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                    //TODO
                }];
            }else{
                NSMutableArray *dataArray = [NSMutableArray array];
                NSMutableArray *timeArray = [NSMutableArray array];
                for (int i = 0; i < dataAry.count; i++) {
                    NSDictionary *dict = dataAry[i];
                    [dataArray addObject:dict[@"performance"]];
                    [timeArray addObject:dict[@"navDate"]];
                }
                htmlDict[@"xData"] = timeArray;
                htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                htmlDict[@"legend"] = [NSArray arrayWithObjects:@"收益走势(%)", nil];
                NSString *str = [self dictionaryToJson:htmlDict];
                NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                    //TODO
                }];
            }
        }else{
            [self getDataOneMounthWithPeriod:proid];
        }
        
    }else{
        if (dataAryTwo.count > 0) {
            if ([_dataDict[@"fundType"] isEqualToString:@"MM"]) {
                NSMutableArray *dataArray = [NSMutableArray array];
                NSMutableArray *timeArray = [NSMutableArray array];
                for (int i = 0; i < dataAryTwo.count; i++) {
                    NSDictionary *dict = dataAryTwo[i];
                    [dataArray addObject:dict[@"earningsPer10000"]];
                    [timeArray addObject:dict[@"navDate"]];
                }
                htmlDict[@"xData"] = timeArray;
                htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                htmlDict[@"legend"] = [NSArray arrayWithObjects:@"万份收益", nil];
                NSString *str = [self dictionaryToJson:htmlDict];
                NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                    //TODO
                }];
            }else{
                NSMutableArray *dataArray = [NSMutableArray array];
                NSMutableArray *timeArray = [NSMutableArray array];
                for (int i = 0; i < dataAryTwo.count; i++) {
                    NSDictionary *dict = dataAryTwo[i];
                    [dataArray addObject:dict[@"nav"]];
                    [timeArray addObject:dict[@"navDate"]];
                }
                htmlDict[@"xData"] = timeArray;
                htmlDict[@"yData"] = [NSArray arrayWithObjects:dataArray, nil];
                htmlDict[@"legend"] = [NSArray arrayWithObjects:@"净值走势(元)", nil];
                NSString *str = [self dictionaryToJson:htmlDict];
                NSString *finalStr = [NSString stringWithFormat:@"initChart(%@)", str];
                [self.webView evaluateJavaScript:finalStr completionHandler:^(id _Nullable response, NSError * _Nullable error) {
                    //TODO
                }];
            }
        }else{
            [self getDataOneMounthWithPeriod:proid];
        }
    }
}

- (IBAction)oneMounth:(UIButton *)sender {
    if (sender.selected == YES) return;
    [self setBtnColorWithBtn:sender];
    [UIView animateWithDuration:0.2 animations:^{
        self.sliderView.centerX = sender.centerX;
    }];
    [self changeChartWithArray:_oneOneMounth withDataArrayTwo:_twoOneMounth withPage:_isOneYes withPorid:@"1"];
}
- (IBAction)threeMounth:(UIButton *)sender {
    if (sender.selected == YES) return;
    [self setBtnColorWithBtn:sender];
    [UIView animateWithDuration:0.2 animations:^{
        self.sliderView.centerX = sender.centerX;
    }];
    [self changeChartWithArray:_oneThreeMounth withDataArrayTwo:_twoThreeMounth withPage:_isOneYes withPorid:@"2"];
}
- (IBAction)oneYear:(UIButton *)sender {
    if (sender.selected == YES) return;
    [self setBtnColorWithBtn:sender];
    [UIView animateWithDuration:0.2 animations:^{
        self.sliderView.centerX = sender.centerX;
    }];
    [self changeChartWithArray:_oneOneYear withDataArrayTwo:_twoOneYear withPage:_isOneYes withPorid:@"4"];
}
- (IBAction)threeYear:(UIButton *)sender {
    if (sender.selected == YES) return;
    [self setBtnColorWithBtn:sender];
    [UIView animateWithDuration:0.2 animations:^{
        self.sliderView.centerX = sender.centerX;
    }];
    [self changeChartWithArray:_oneThreeYear withDataArrayTwo:_twoThreeYear withPage:_isOneYes withPorid:@"5"];
}
- (IBAction)fiveYear:(UIButton *)sender {
    if (sender.selected == YES) return;
    [self setBtnColorWithBtn:sender];
    [UIView animateWithDuration:0.2 animations:^{
        self.sliderView.centerX = sender.centerX;
    }];
    [self changeChartWithArray:_oneFiveYear withDataArrayTwo:_twoFiveYear withPage:_isOneYes withPorid:@"6"];
}
- (IBAction)forverClick:(UIButton *)sender {
    if (sender.selected == YES) return;
    [self setBtnColorWithBtn:sender];
    [UIView animateWithDuration:0.2 animations:^{
        self.sliderView.centerX = sender.centerX;
    }];
    
    [self changeChartWithArray:_oneEver withDataArrayTwo:_twoEver withPage:_isOneYes withPorid:@"8"];
}

- (void)setBtnColorWithBtn:(UIButton *)sender{
    [self deleteWebCache];
    for (int i = 0; i < self.btnArray.count; i++) {
        UIButton *btn = _btnArray[i];
        [btn setTitleColor:ZKcolor(170, 170, 170) forState:UIControlStateNormal];
    }
    [sender setTitleColor:ZKcolor(184, 27, 36) forState:UIControlStateNormal];
    [UIView animateWithDuration:0.2 animations:^{
        self.sliderView.centerX = sender.centerX;
    }];
}

- (void)deleteWebCache {
    
    if([[UIDevice currentDevice].systemVersion floatValue] >=9.0) {
        
        NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
        
        NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
        [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
            
        }];
        
    }else{
        
        NSString*libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES)objectAtIndex:0];
        
        NSString*cookiesFolderPath = [libraryPath stringByAppendingString:@"/Cookies"];
        
        NSError*errors;
        
        [[NSFileManager defaultManager]removeItemAtPath:cookiesFolderPath error:&errors];
        
    }
    
}

    

@end
